<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activIdsAdmin']))
{
	header("Location:checkLogin.php");
}
else
{
  if(isset($_REQUEST['submit']))
  {
    	$name       = isset($_POST['itemName']) ? $_POST['itemName'] : "";
    	$itemPrice  = isset($_POST['itemPrice']) ? $_POST['itemPrice'] : 0;
  
      $insertPrice = "INSERT INTO price (itemName,itemPrice)
                               VALUES ('".$name."',".$itemPrice.")";
      $insertPriceRes = mysql_query($insertPrice);
      if(!$insertPriceRes)
      {
      	die ("Insert Query Not Insertd :" .mysql_error());    
      }
      else
      {
       // header("Location:priceList.php");
      }
  }
  $i=0;
  $priceArray = array();
  $selectUser = "SELECT priceId,itemName,itemPrice
                   FROM price";
  $selectUserRes = mysql_query($selectUser);
  while($priceRow = mysql_fetch_array($selectUserRes))
  {
  	$priceArray[$i]['priceId']     = $priceRow['priceId'];
  	$priceArray[$i]['itemName']    = $priceRow['itemName'];
  	$priceArray[$i]['itemPrice']   = $priceRow['itemPrice'];
  	$i++;
  }
  
  $j=0;
  $itemArray = array();
  $selectitem = "SELECT itemId,itemName
                   FROM item";
  $selectitemRes = mysql_query($selectitem);
  while($itemRow = mysql_fetch_array($selectitemRes))
  {
  	$itemArray['itemId'][$j]   = $itemRow['itemId'];
  	$itemArray['itemName'][$j] = $itemRow['itemName'];
  	$j++;
  }
  include("bottom.php");
  $smarty->assign("itemArray",$itemArray);
  $smarty->assign("priceArray",$priceArray);
  $smarty->display("priceList.tpl");
}
?>